package com.packtpublishing.tddjava.ch04ship;

public class Ship {

    private Location location;
    private Planet planet;

    public Ship(Location location, Planet planet) {
        this.location = location;
        this.planet = planet;
    }

    public Location getLocation() {
        return location;
    }

    public void setLocation(Location location) {
        this.location = location;
    }

    public Planet getPlanet() {
        return planet;
    }

    public void setPlanet(Planet planet) {
        this.planet = planet;
    }

    //==================================
    public boolean moveForward() {
        return location.forward(planet.getMax(),planet.getObstacles());
    }

    public boolean moveBackward() {
        return location.backward(planet.getMax(),planet.getObstacles());
    }

    public void turnLeft() {
        location.turnLeft();
    }

    public void turnRight() {
        location.turnRight();
    }

    public String receiveCommands(String commands) {
        String result = "";
        for (char c : commands.toCharArray()) {
            switch (c) {
                case 'f':
                    result+= moveForward()?"O":"X";
                    break;
                case 'b':
                    result+= moveBackward()?"O":"X";
                    break;
                case 'r':
                    turnRight();
                    result+= "O";
                    break;
                case 'l':
                    turnLeft();
                    result+= "O";
                    break;
                default:
            }
        }
        return result;
    }
}
